﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Purchase;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.QRUPCSearch
{
    public class MaterialSSearchHandler : IRequestHandler<MaterialSSearchCommand, PageDTO<MaterialSDTO>>
    {
        private readonly IBateRepository<MaterialSDTO> _material;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="material"></param>
        public MaterialSSearchHandler(IBateRepository<MaterialSDTO> material)
        {
            _material = material;
        }
        /// <summary>
        /// 入库统计
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<PageDTO<MaterialSDTO>> Handle(MaterialSSearchCommand request, CancellationToken cancellationToken)
        {

            DapperHelper helper = new DapperHelper();
            MaterialSDTO materials = new MaterialSDTO();
            PageDTO<MaterialSDTO> dto = new PageDTO<MaterialSDTO>();
            string conn = helper.MangoMesWrite;
            string sql = "select a.MaterialTime,productmanage.productManageName,productmanage.productManageNode,productmanage.ProductManageNumber,productmanage.unites,a.Num,warehouselist.StashName from material a inner join productmanage on a.ProductManageId=productmanage.ProductManageId join warehouselist on a.StashId=warehouselist.StashId join purchasestorage on a.PurchaseNo=purchasestorage.PurchaseNo";
            var res = _material.GetAll(sql, materials, conn).ToList();
            dto.Data = res;
            return dto;
        }
    }
}
